package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    private Button button;
    private Button button2;
    private Button button3;
    private Button button4;
    private Button button5;
    private Button button6;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        button = (Button) findViewById(R.id.button);

        button2=(Button) findViewById(R.id.button2);
        button2.setOnClickListener(new View.OnClickListener(){

            public void onClick(View view){
                SimpleDialogFragment dialog = new SimpleDialogFragment();
                dialog.show(getSupportFragmentManager(),"simple");
            }
        });

        button3=(Button) findViewById(R.id.button3);
        button3.setOnClickListener(new View.OnClickListener(){

            public void onClick(View view){
                ChoiceDialogFragment dialog = new ChoiceDialogFragment();
                dialog.setListener(new ChoiceDialogFragment.NotifyDialogListener(){
                    @Override
                    public void onDialogPositiveClicked(String gender) {
                        Toast.makeText(getApplicationContext(),"你选择了"+gender,Toast.LENGTH_SHORT).show();
                    }
                });
                dialog.show(getFragmentManager(),"choice");
            }
        });


        button4 = (Button) findViewById(R.id.button4);
        button4.setOnClickListener(new View.OnClickListener(){

            public void onClick(View view){
                DanChoiceDialogFragment dialog = new DanChoiceDialogFragment();

                dialog.show(getFragmentManager(),"choice");
            }
        });


        button5 = (Button) findViewById(R.id.button5);
        button5.setOnClickListener(new View.OnClickListener(){

            public void onClick(View view){
                DuoChoiceDialogFragment dialog = new DuoChoiceDialogFragment();

                dialog.show(getFragmentManager(),"choice");
            }
        });
        //旧版

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog dialog;
                dialog = new AlertDialog.Builder(MainActivity.this).setTitle("旧版对话框")
                        .setMessage("这是旧版对话框，使用很简单\n但是没有自动支持屏幕翻转！")
                        .setPositiveButton("确定",new DialogInterface.OnClickListener(){
                            public void  onClick(DialogInterface dialog, int which) {
                                Toast.makeText(getApplicationContext(),"你确定了!",Toast.LENGTH_SHORT).show();
                            }
                        })
                        .setNegativeButton("no",new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,int which) {
                                Toast.makeText(getApplicationContext(),"你取消了！",Toast.LENGTH_SHORT).show();
                            }
                        })
                        .create();
                dialog.show();
            }
        });
        button6=(Button) findViewById(R.id.button6);
        button6.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                FireMissilesDialogFragment dialog = new FireMissilesDialogFragment();
                dialog.setListener(new FireMissilesDialogFragment.NotifyDialogListener() {
                    @Override
                    public void onDialogPositiveClicked(String text1, String text2) {
                        Toast.makeText(getApplicationContext(), "用户名：" + text1 + "\n密码：" + text2, Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onDialogNegativeClicked() {
                        Toast.makeText(getApplicationContext(), "你取消了", Toast.LENGTH_SHORT).show();
                    }
                });
                dialog.show(getSupportFragmentManager(),"FireMissilesDialogFragment");
            }
        });
    }


}



